package org.noote.libs.widget;

public class Widget_Pad extends Widget_Window {

	Widget_Label _label = null;
	Widget_Icon _icon = null;
	
	protected boolean _bOnOffMode=false;
	protected boolean _bIsOn=false;
	
	protected boolean _bTouchMode=true;
	
	public Widget_Pad(Widget_Window parent) {
		super(parent);
	}
	
	public Widget_Pad(Widget_Window parent, WidgetTheme theme) {
		super(parent, theme);
	}
	
	@Override
	public void create()
	{
		super.create(0, 0, _theme.padSizeX, _theme.padSizeY);
		
		_label = new Widget_Label(this, _theme);
		_label.create();
		_icon = new Widget_Icon(this, _theme);
		_icon.create();
		add(_label);
		add(_icon);
		
		setBackground(_theme._textures.getTextureID(WidgetTheme.TEXTID_PAD));
		setBackgroundColor(_theme.colorSkinDefault);
		
		_label.setTextAlign(Widget_Label._ALIGN_CENTER);
		_label.setTextFont(_theme.fontRegular16);
		_label.setTextPosition(_theme.padSizeX/2, 24, _theme.padSizeX/2-10, 16);
		_icon.setIconPosition(_theme.padSizeX/2, _theme.padSizeY/2+16);
	}
	
	@Override
	protected void _checkButtons() {
		super._checkButtons();
		
		if(_bTouchMode &&
				(_iState == TOUCH_PRESSED
				|| _iState == TOUCH_RELEASED))
		{
			_bNewEvent = true;
		}
		if(_bOnOffMode)
		{
			if(_iState == TOUCH_PRESSED && _iOldState == TOUCH_RELEASED)
			{
				if(isOn()) setOff();
				else setOn();
			}
		}
	}
	
	public Widget_Icon getIcon() {
		return _icon;
	}
	public Widget_Label getLabel() {
		return _label;
	}
	
	public void setText(String sText)
	{
		_label.setText(sText);
	}
	public void setSystemIcon(int iID)
	{
		_icon.setSystemIcon(iID);
	}
	public void setIcon(int iID)
	{
		_icon.setIcon(iID);
	}
	
	public void setOn()
	{
		_icon.setSystemIcon(WidgetTheme.ICON_ON);
		_bIsOn = true;
		_bOnOffMode=true;
		refresh();
	}
	public void setOff()
	{
		_icon.setSystemIcon(WidgetTheme.ICON_OFF);
		_bIsOn = false;
		_bOnOffMode=true;
		refresh();
	}
	public boolean isOn()
	{
		return _bIsOn;
	}
}
